package com.dhcc.DRGsHosp.facade.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;

import com.dhcc.DRGsHosp.application.MrqDictWeightApplication;
import com.dhcc.DRGsHosp.core.domain.MrqScore;
import com.dhcc.DRGsHosp.facade.MrqScoreFacade;
import com.dhcc.DRGsHosp.infra.util.MonitorResultUtil;

/**
 *
 * @Description:    首页质控得分 facadeImpl
 * @param:
 * @return:
 * @auther: chenhanlin
 * @date: 2018/7/26 16:21
 */
@Named("drgsHospMrqScoreFacadeImpl20181212")
public class MrqScoreFacadeImpl implements MrqScoreFacade {
	
    @Autowired
    private MrqDictWeightApplication mrqDictWeightApplication ;

    @Override
    public MrqScore initializeFullScore(String hospName) {
    	if(null == hospName || "".equals(hospName)){
    		hospName = mrqDictWeightApplication.getHospName();
    	}
		List<Map<String, Object>> scoreMap = mrqDictWeightApplication.getAllMrqDictWeight(hospName);
		MrqScore score = new MrqScore() ;
		//Map数据格式为  大类编码 SCORE_CODE:BASICINFO,大类名称 SCORE_NAME:'患者基本信息',大类分数 SCORE_SCORE:18.0
		//大类里面的分类编码 WEIGHT_CODE:A,分类名称 WEIGHT_NAME:A类,分类分数 WEIGHT_SCORE:8.0,分类保底分数(分类的最低得分不能小于这个分数) MIN_SCORE:2.0
		score.setScoreMap(scoreMap);

        if(null != scoreMap && scoreMap.size()>0){
        	Map<String,Double> totalScoreMap = new LinkedHashMap<String,Double>();
        	Map<String,Double> partScoreMap = new LinkedHashMap<String,Double>();
        	Map<String,Double> minScoreMap = new LinkedHashMap<String,Double>();
        	//所有大类
        	Map<String,String> wholeClass = new LinkedHashMap<String,String>();
        	//所有分类
        	Map<String,String> partClass = new LinkedHashMap<String,String>();
        	for(Map<String,Object> map:scoreMap){
        		String totalKey = (String)map.get("SCORE_CODE");
        		Double totalScore = MonitorResultUtil.objectToDouble(map.get("SCORE_SCORE"));
        		//如  totalScoreMap.put("BASICINFO", 18.0);
        		totalScoreMap.put(totalKey, totalScore);
        		String partKey = totalKey+"@@"+(String)map.get("WEIGHT_CODE");
        		Double partScore = MonitorResultUtil.objectToDouble(map.get("WEIGHT_SCORE"));
        		//如  partScoreMap.put("BASICINFO@@A", 8.0);
        		partScoreMap.put(partKey, partScore);
        		Double partMinScore = MonitorResultUtil.objectToDouble(map.get("MIN_SCORE"));
        		//如  minScoreMap.put("BASICINFO@@A", 2.0);
        		minScoreMap.put(partKey, partMinScore);
        		
            	wholeClass.put(totalKey,(String)map.get("SCORE_NAME"));
        		String partMapKey = (String)map.get("WEIGHT_CODE");
            	partClass.put(partMapKey,(String)map.get("WEIGHT_NAME"));
        	}

        	//大类满分明细
        	score.setTotalScoreMap(totalScoreMap);
        	//分类满分明细
        	score.setPartScoreMap(partScoreMap);
        	//分类保底得分明细
        	score.setMinScoreMap(minScoreMap);
        	score.setWholeClass(wholeClass);
        	score.setPartClass(partClass);
        }
        return score;
    }
}
